<?php
	namespace Admin\Controller;

	class AddverController extends  CommonController{
		public function index(){
			$model=D('Addver');
			$list=$model->getAll();
			foreach($list as &$val){
			$val['name']='/Public/Uploads/'.substr($val['name'],0,4).'/'.substr($val['name'],4,2).'/'.substr($val['name'],6,2).'/80_'.$val['name'];
			}
			$this->assign('list',$list);
			$this->display();
		}

		public function add(){
		
			if (empty($_POST)) {
				$model=D('Addver');
				$this->display();
				return false;
			}
			$file=new GoodsController;
			$filename=$file->upload();
		
			$model=D('Addver');
			$data['address']=$_POST['address'];
			$data['status']=$_POST['status'];
			$res=$model->setadd($data,$filename);

			if($res)
			{
				$this->success('添加成功',U('Index'),2);
				return false;
			}else{
				$this->setunlink($filename);
				$this->error('添加失败');
			}



		}
		public function status(){
			$id=$_GET['id'];
			$status=$_GET['status'];
			$AddverModel=D('Addver');
			$res=$AddverModel->change($status,$id);
			$this->redirect('index');
		}
		public function deleted(){
			$id=$_GET['id'];
			$goods = M('addver');
			$res=$goods->where('id='.$id)->delete();
			if($res){
				$this->success('删除成功',U('index'));
			}else{
				$this->error('删除失败');
			}

	}
	}